;
(function (window, angular) {
    'use strict';
    angular.module("Controller.Stock.Inventory", [])
        .controller("InventoryCtrl", ["$scope", "$state", "ybWidget", "ybHttp", "MESG_TYPE", "$timeout", "$filter", "EventBus", "UserContextService", function ($scope, $state, ybWidget, ybHttp, MESG_TYPE, $timeout, $filter, EventBus, UserContextService) {
            $scope.activeFlag = [true, false, false];
            $scope.markInfo = {
                allChecked: false
            };
            $scope.showDatepicker = false;
            $scope.showDatepickerBegin = false;
            $scope.showDatepickerEnd = false;
            $scope.pageInfo = {
                totalPages: 1,
                totalRows: 0,
                pageSize: 10,
                curPage: 1
            };
            $scope.materialPageInfo = {
                totalPages: 1,
                totalRows: 0,
                pageSize: 10,
                curPage: 1
            };
            $scope.dataSelected = {
                keeper: {},
                location: {},
                locationCode: ''
            };
            $scope.submitted = false;
            $scope.toolbarConfig = {
                showAdvanceSearch: false,
                showColConfig: false
            };
            $scope.condition = {};
            $scope.dataList = [];
            $scope.detailInfo = {
                inventoryCheckDetailVOS: []
            };
            $scope.tabFlag = {};
            var tabFlag = {
                0: "新增",
                1: "编辑"
            };
            $scope.checkStatues = [{
                    name: '未盘点',
                    id: 0
                },
                {
                    name: '盘点启动',
                    id: 1
                },
                {
                    name: '盘点结束',
                    id: 2
                },
                {
                    name: '盘点终止',
                    id: 3
                }
            ];
            $scope.tableConfig = {
                scrollWidth: 1520,
                fixedWidth: 290,
                tableCol: [
                    {
                        type: "",
                        name: "盘点单号",
                        dataField: "checkOrderNo",
                        width: 150,
                        isShow: true,
                        isFixed: false,
                        clickFn: "viewDetail",
                    },
                    {
                        type: "",
                        name: "盘点描述",
                        dataField: "checkOrderDes",
                        width: 150,
                        isShow: true,
                        isFixed: false,
                    },
                    {
                        type: "",
                        name: "计划盘点日期",
                        dataField: "plannedDateShow",
                        width: 150,
                        isShow: true,
                        isFixed: false,
                    },
                    {
                        type: "",
                        name: "盘点状态",
                        dataField: "statusShow",
                        width: 100,
                        isShow: true,
                        isFixed: false,
                    },
                    {
                        type: "",
                        name: "盘点类型",
                        dataField: "checkTypeShow",
                        width: 100,
                        isShow: true,
                        isFixed: false,
                    },
                    {
                        type: "",
                        name: "仓库",
                        dataField: "warehouseCode",
                        width: 100,
                        isShow: true,
                        isFixed: false,
                    },
                    {
                        type: "",
                        name: "仓库描述",
                        dataField: "warehouseDes",
                        width: 100,
                        isShow: true,
                        isFixed: false,
                    },
                    {
                        type: "",
                        name: "库区",
                        dataField: "locationCodesStr",
                        width: 150,
                        isShow: true,
                        isFixed: false,
                    },
                    {
                        type: "",
                        name: "启动人",
                        dataField: "startName",
                        width: 80,
                        isShow: true,
                        isFixed: false,
                    },
                    {
                        type: "attach",
                        name: "附件",
                        dataField: "attachName",
                        width: 100,
                        isShow: true,
                        isFixed: false,
                        clickFn: "viewAttach",
                    },
                    {
                        type: "",
                        name: "创建人",
                        dataField: "createName",
                        width: 100,
                        isShow: true,
                        isFixed: false,
                    },
                    {
                        type: "",
                        name: "制单时间",
                        dataField: "createDateShow",
                        width: 100,
                        isShow: true,
                        isFixed: false,
                    },
                    {
                        type: "operate",
                        name: "操作",
                        dataField: "",
                        width: 150,
                        isShow: true,
                        isFixed: true,
                    }
                ]
            };

            $scope.materielTableConfig = {
                scrollWidth: 600,
                tableCol: [
                    {
                        name: "盘点条码",
                        width: 150,
                        dataField: "barCode",
                        isShow: true
                    },
                    {
                        name: "零件编号",
                        width: 150,
                        dataField: "materialsNo",
                        isShow: true
                    },
                    {
                        name: "零件中文名",
                        width: 150,
                        dataField: "materialsDes",
                        isShow: true
                    },
                    {
                        name: "储位",
                        width: 150,
                        dataField: "locationCode",
                        isShow: true
                    },
                    {
                        name: "数量",
                        width: 100,
                        dataField: "amount",
                        isShow: true
                    },
                    {
                        name: "保管员",
                        width: 100,
                        dataField: "userName",
                        isShow: true
                    },
                    {
                        name: "产品组",
                        width: 150,
                        dataField: "productGroupCode",
                        isShow: false
                    },
                    {
                        name: "零件用途",
                        width: 150,
                        dataField: "materialUseCode",
                        isShow: false
                    }
                ]
            };
            $scope.materielTableConfigTwo = {
                scrollWidth: 300,
                tableCol: [
                    {
                        name: "仓库编码",
                        width: 152,
                        dataField: "warehouseCode"
                    },
                    {
                        name: "仓库描述",
                        width: 152,
                        dataField: "description"
                    },
                ]
            };
            $scope.materielDetailTableConfig = {
                scrollWidth: 1050,
                tableCol: [
                    {
                        name: "盘点条码",
                        width: 150,
                        dataField: "barCode"
                    },
                    {
                        name: "零件编号",
                        width: 150,
                        dataField: "materialsNo"
                    },
                    {
                        name: "零件中文名",
                        width: 150,
                        dataField: "materialsDes"
                    },
                    {
                        name: "储位",
                        width: 100,
                        dataField: "loactionCode"
                    },
                    {
                        name: "原始数量",
                        width: 100,
                        dataField: "sysAmount"
                    },
                    {
                        name: "盘点数量",
                        width: 100,
                        dataField: "actAmount"
                    },
                    {
                        name: "保管员",
                        width: 100,
                        dataField: "depositaryName"
                    },
                    {
                        name: "盘点状态",
                        width: 100,
                        dataField: "stateShow"
                    },
                    {
                        name: "盘点人",
                        width: 100,
                        dataField: "inventoryUserName"
                    },
                    {
                        name: "产品组",
                        width: 150,
                        dataField: "productGroupCode",
                    },
                    {
                        name: "零件用途",
                        width: 150,
                        dataField: "materialUseCode",
                    }
                ]
            };

            var btnPermissionCode = {
                inventoryAdd: window.ActionCode.inventoryAdd,
                inventoryDel: window.ActionCode.inventoryDel,
                inventoryOpen: window.ActionCode.inventoryOpen,
                inventoryClose: window.ActionCode.inventoryClose,
                inventoryPrint: window.ActionCode.inventoryPrint,
                inventoryTermination: window.ActionCode.inventoryTermination,
                inventoryImportAttach:window.ActionCode.inventoryImportAttach,
            };

            $scope.btnPermission = {
                inventoryAdd: true,
                inventoryDel: true,
                inventoryOpen: true,
                inventoryClose: true,
                inventoryPrint: true,
                inventoryTermination: true,
                inventoryImportAttach:true
            };

            function setBtnPermission() {
                for (var key in btnPermissionCode) {
                    $scope.btnPermission[key] = UserContextService.CheckPermission([btnPermissionCode[key]]);
                }
            }

            $scope.setFixedWidth = function () {
                $scope.tbStyle = {
                    scrollLeft: {
                        left: $scope.tableConfig.fixedWidth + "px"
                    }
                };
            };

            $scope.changeTab = function (index) {
                $scope.activeFlag = [false, false, false];
                $scope.activeFlag[index] = true;
                $scope.submitted = false;
                switch (index) {
                    case 0:
                        initData();
                        break;
                    case 1:
                        getWarehouse();
                        break;
                    case 2:
                        break;
                    default:
                        break;
                }
            };

            function initData() {
                $scope.tabFlag = {};
                $scope.detailInfo = {
                    inventoryCheckDetailVOS: []
                };
                $scope.materialPageInfo = {
                    totalPages: 1,
                    totalRows: 0,
                    pageSize: 10,
                    curPage: 1
                };

                $scope.sel = { productGroupObj: {} };
            }

            function getDataList(curPage) {
                var service = "device";
                var reqUrl = "/inventoryCheck/list";
                var param = {};
                param.pageSize = $scope.pageInfo.pageSize;
                if (!!curPage) {
                    $scope.pageInfo.curPage = curPage;
                }
                param.pageNum = $scope.pageInfo.curPage;
                $scope.condition.startDate = new Date($scope.condition.startDate).getTime();
                $scope.condition.endDate = new Date($scope.condition.endDate).getTime();
                param.filters = angular.copy($scope.condition);
                ybHttp.Post(service, reqUrl, param).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return;
                    }
                    angular.forEach(resp.value.list, function (item) {
                        item.isChecked = false;
                        item.createDateShow = $filter("YbDate")(item.createDate, 'yyyy-MM-dd HH:mm:ss');
                        item.plannedDateShow = $filter("YbDate")(item.plannedDate);
                        item.statusShow = $filter("inventoryCheck")(item.status);
                        item.checkTypeShow = $filter("ProgressStatus")(item.checkType, "checkType");
                    });
                    $scope.pageInfo.totalRows = resp.value.total;
                    $scope.pageInfo.totalPages = resp.value.pages;
                    $scope.dataList = resp.value.list;
                });
            }

            $scope.switchToolbar = function (toolbar) {
                if (!!$scope.toolbarConfig["show" + toolbar]) {
                    $scope.toolbarConfig["show" + toolbar] = false;
                } else {
                    $timeout(function () {
                        $scope.toolbarConfig["show" + toolbar] = true;
                    });
                }
            };

            $scope.selectRow = function (index) {
                $scope.markInfo.cueRow = index
            };

            $scope.tdClick = function (item, fnType) {
                switch (fnType) {
                    case "viewDetail":
                        viewDetail(item);
                        break;
                    case "viewAttach":
                        viewAttach(item);
                        break;
                    default:
                        break;
                }
            };

            $scope.search = function (curpage) {
                getDataList(curpage);
            };

            $scope.reset = function () {
                $scope.condition = {};
            };

            $scope.selectAll = function () {
                for (var i = 0, len = $scope.dataList.length; i < len; i++) {
                    $scope.dataList[i].isChecked = $scope.markInfo.allChecked;
                }
            };

            function getWarehouse() {
                var service = "device";
                var reqUrl = "/warehouse/listWarehouses";
                var param = {
                    pageNum: 0,
                    pageSize: 0
                };
                ybHttp.Get(service, reqUrl, param).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return false;
                    }
                    $scope.warehouseList = resp.value.list;
                })
            }

            $scope.selectWarehouse = function () {
                ybWidget.WarehouseSelector().then(function (data) {
                    $scope.detailInfo.warehouseCode = data.warehouseCode;
                    getWarehouse();
                    changeStorage();
                })
            };

            $scope.clearWarehouse = function () {
                $scope.detailInfo.warehouseCode = "";
            };

            function changeStorage () {
                angular.forEach($scope.warehouseList, function (item) {
                    if (item.warehouseCode == $scope.detailInfo.warehouseCode) {
                        $scope.detailInfo.warehouseId = item.id;
                    }
                });
                if ($scope.detailInfo.checkType === 1) {
                    $scope.dataSelected.keeper = {};
                }
                if ($scope.detailInfo.checkType === 2) {
                    $scope.dataSelected.location = {};

                    $scope.dataSelected.locationCode = '';

                    if (!$scope.detailInfo.warehouseCode) {
                        $scope.detailInfo.warehouseId = "";
                    }
                }
                $scope.detailInfo.inventoryCheckDetailVOS = [];
                $timeout(function () {
                    EventBus.Publish("getMaterial");
                });
            };

            function checkAll() {
                var selectAll = false;
                for (var i = 0, len = $scope.dataList.length; i < len; i++) {
                    if (!$scope.dataList[i].isChecked) {
                        selectAll = false;
                        break;
                    }
                    selectAll = true;
                }
                return selectAll;
            }
            $scope.checkDate = function (item, start, end) {
                if ((angular.isUndefined(item[start]) || !item[start]) && (angular.isUndefined(item[end]) || !item[end])) {
                    return;
                }
                if (!!item[start] && (angular.isUndefined(item[end]) || !item[end])) {
                    item[start] = ybWidget.FormatStartDate(item[start]);
                    return;
                }
                if ((angular.isUndefined(item[start]) || !item[start]) && !!item[end]) {
                    item[end] = ybWidget.FormatEndDate(item[end]);
                    return;
                }
                var tmpTime = item[start];
                if (item[end] < item[start]) {
                    item[start] = ybWidget.FormatStartDate(item[end]);
                    item[end] = ybWidget.FormatEndDate(tmpTime);
                } else {
                    item[start] = ybWidget.FormatStartDate(item[start]);
                    item[end] = ybWidget.FormatEndDate(item[end]);
                }
            };
            $scope.selectSingle = function (item) {
                if (!item.isChecked) {
                    $scope.markInfo.allChecked = false;
                } else {
                    if (!checkAll()) {
                        $scope.markInfo.allChecked = false;
                    } else {
                        $scope.markInfo.allChecked = true;
                    }
                }
            };
            $scope.warehouseTypeList = [
            ];
            $scope.changeType = function (type) {
                if (type == $scope.detailInfo.checkType) {
                    return;
                }
                $scope.materialPageInfo = {
                    totalPages: 1,
                    totalRows: 0,
                    pageSize: 10,
                    curPage: 1
                };

                $scope.detailInfo.warehouseCode = "";
                $scope.dataSelected.keeper = {};
                $scope.dataSelected.location = {};

                $scope.dataSelected.locationCode = "";

                $scope.detailInfo.checkOrderDes = "";
                $scope.detailInfo.plannedDate = "";
                $scope.detailInfo.inventoryCheckDetailVOS = [];
                if ($scope.detailInfo.checkType === 3) {
                    EventBus.Publish("clearMaterial");
                }

                handleSpecialTabCol(type);
            };

            function handleSpecialTabCol(curCheckType) {
                const showFlag = curCheckType == 0 || curCheckType == 5
                ybWidget.GetTableCol($scope.materielTableConfig.tableCol, 'productGroupCode').isShow = showFlag;
                ybWidget.GetTableCol($scope.materielTableConfig.tableCol, 'materialUseCode').isShow = showFlag;
            }

            $scope.addData = function () {
                $scope.tabFlag.type = 0;
                $scope.tabFlag.name = tabFlag[0];
                $scope.detailInfo.checkType = 0;
                $scope.changeTab(1);
                getWarehouseType();

                handleSpecialTabCol(0);
            };

            $scope.start = function (item) {
                var service = "device";
                var reqUrl = "/inventoryCheck/runCheck";
                var param = {};
                param.id = item.id;

                ybHttp.Post(service, reqUrl, param).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return;
                    }
                    ybWidget.ShowToaster('success', '操作成功');
                    getDataList();
                });
            };

            $scope.stop = function (item) {
                var service = "device";
                var reqUrl = "/inventoryCheck/stopCheck";
                var param = {};
                param.id = item.id;
                ybWidget.ShowMessage("确定要关闭盘点任务吗？", MESG_TYPE.Ask).then(function () {
                    ybHttp.Post(service, reqUrl, param).then(function (resp) {
                        if (resp.code !== 0) {
                            ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                            return;
                        }
                        ybWidget.ShowToaster('success', '操作成功');
                        getDataList();
                    });
                }, function () {

                })
            };

            $scope.delData = function (delType, id) {
                var service = "device";
                var reqUrl = "/inventoryCheck/remove";
                var param = {};
                param.ids = [];

                if (delType === "single") {
                    param.ids.push(id);
                }

                if (delType === "batch") {
                    for (var i = 0, len = $scope.dataList.length; i < len; i++) {
                        if (!!$scope.dataList[i].isChecked) {
                            param.ids.push($scope.dataList[i].id);
                        }
                    }
                }
                if (param.ids.length === 0) {
                    ybWidget.ShowMessage('请选择需要删除的行');
                    return;
                }

                ybWidget.ShowMessage("确定要删除吗？", MESG_TYPE.Ask).then(function () {
                    ybHttp.Post(service, reqUrl, param.ids).then(function (resp) {
                        if (resp.code !== 0) {
                            ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                            return;
                        }
                        ybWidget.ShowToaster('success', '操作成功');
                        getDataList();
                    })
                }, function () {

                })
            };
            $scope.termination = function (id) {
                var service = "device";
                var reqUrl = "/inventoryCheck/cancelCheck?" + 'id=' + id;

                ybWidget.ShowMessage("确定要终止吗？", MESG_TYPE.Ask).then(function () {
                    ybHttp.Post(service, reqUrl).then(function (resp) {
                        if (resp.code !== 0) {
                            ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                            return;
                        }
                        ybWidget.ShowToaster('success', '操作成功');
                        getDataList();
                    })
                }, function () {

                })
            };
            $scope.printBill = function (item) {
                var param = {
                    printType: "Inventory",
                    cusParam: { inventoryCheckId: item.id }
                };
                ybWidget.SetIsPrintOrPreview(param);
            };

            $scope.preview = function () {
                if (!$scope.detailInfo.warehouseCode && $scope.detailInfo.checkType != 4 && $scope.detailInfo.checkType != 5) {
                    ybWidget.ShowToaster('error', '请选择仓库');
                    return;
                }
                var service = "device";
                var reqUrl = "/inventoryCheck/invenitoryMaterialsList";
                var param = {
                    filters: {
                        warehouseCode: $scope.detailInfo.warehouseCode
                    }
                };
                param.pageSize = $scope.materialPageInfo.pageSize;
                param.pageNum = $scope.materialPageInfo.curPage;
                switch ($scope.detailInfo.checkType) {
                    case 1:
                        param.filters.userIds = $scope.dataSelected.keeper.list;
                        break;
                    case 2:
                        param.filters.locationCodes = $scope.dataSelected.location.list;
                        param.filters.locationCode = $scope.dataSelected.locationCode;
                        param.filters.shlefNo = $scope.detailInfo.shlefNo;
                        break;
                    case 4:
                        reqUrl = "/inventoryCheck/invenitoryWarehouseList";
                        param.filters.warehouseType = $scope.detailInfo.warehouseType;
                        break;
                    case 5:
                        param.filters.warehouseCode = undefined
                        param.filters.productGroupCode = $scope.sel.productGroupObj.code
                        break;
                    default:
                        break;
                }
                ybHttp.Post(service, reqUrl, param).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return;
                    }
                    angular.forEach(resp.value.list, function (item) {
                        item.materialsDes = item.materialsName;
                    });
                    $scope.materialPageInfo.totalRows = resp.value.total;
                    $scope.materialPageInfo.totalPages = resp.value.pages;
                    $scope.detailInfo.inventoryCheckDetailVOS = resp.value.list;
                });
            };

            function viewDetail(item) {
                var service = "device";
                var reqUrl = "/inventoryCheck/item";
                var param = {};
                param.inventoryCheckId = item.id;
                ybHttp.Get(service, reqUrl, param).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return;
                    }
                    $scope.changeTab(2);
                    $scope.detailInfo = resp.value;
                    getDetailList();
                });
            }
            function getWarehouseType(){
                var service = "device";
                var reqUrl = "/serviceBasicDataAgent/searchList";
                var param = {pCode:"WAREHOUSE_TYPE"};
                ybHttp.Post(service, reqUrl, param).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return;
                    }
                    $scope.warehouseTypeList =resp.value;
                });
            }

            $scope.detailSearch = function () {
                getDetailList();
            };

            function getDetailList() {
                var service = "device";
                var reqUrl = "/inventoryCheck/itemList";
                var param = {
                    filters: {}
                };
                param.filters.checkOrderNo = $scope.detailInfo.checkOrderNo;
                param.pageSize = $scope.materialPageInfo.pageSize;
                param.pageNum = $scope.materialPageInfo.curPage;
                ybHttp.Post(service, reqUrl, param).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return;
                    }
                    angular.forEach(resp.value.list, function (item) {
                        item.stateShow = $filter('checkState')(item.resultType);
                    });
                    $scope.materialPageInfo.totalRows = resp.value.total;
                    $scope.materialPageInfo.totalPages = resp.value.pages;
                    $scope.detailInfo.detailList = resp.value.list;
                });
            }

            $scope.selMateriel = function (e) {
                if (!$scope.detailInfo.warehouseCode) {
                    ybWidget.ShowToaster('error', '请选择仓库');
                    return;
                }
                if (!!$scope.toolbarConfig.showMateriel) {
                    e.stopPropagation();
                } else {
                    $timeout(function () {
                        $scope.toolbarConfig.showMateriel = true;
                        EventBus.Publish("getMaterial");
                    });
                }
            };

            $scope.saveData = function (isValid) {
                if (!isValid) {
                    $scope.submitted = true;
                    return;
                }
                if ($scope.detailInfo.checkType == 1 && (!$scope.dataSelected.keeper.list || $scope.dataSelected.keeper.list.length == 0)) {
                    $scope.submitted = true;
                    return;
                }
                if ($scope.detailInfo.checkType == 2 && (!$scope.dataSelected.location.list || $scope.dataSelected.location.list.length == 0)) {
                    $scope.submitted = true;
                    return;
                }
                if ($scope.detailInfo.inventoryCheckDetailVOS.length == 0) {
                    ybWidget.ShowMessage('没有零件，无法进行盘点', MESG_TYPE.Error);
                    $scope.submitted = true;
                    return;
                }
                var service = "device";
                var reqUrl = "/inventoryCheck/add";
                var param = $scope.detailInfo;

                if ($scope.detailInfo.checkType == 1) {
                    param.userIds = $scope.dataSelected.keeper.list;
                }
                if ($scope.detailInfo.checkType == 2) {
                    param.locationCodes = $scope.dataSelected.location.list;

                    param.locationCode = $scope.dataSelected.locationCode;

                    param.shlefNo = $scope.detailInfo.shlefNo;
                }
                if ($scope.detailInfo.checkType == 3) {
                    param.materialsList = [];
                    angular.forEach($scope.detailInfo.inventoryCheckDetailVOS, function (item) {
                        param.materialsList.push(item.barCode);
                    });
                }
                if ($scope.detailInfo.checkType == 5) {
                    param.warehouseCode = undefined
                    param.productGroupCode = $scope.sel.productGroupObj.code
                }
                ybHttp.Post(service, reqUrl, param).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return;
                    }
                    if($scope.detailInfo.checkType != 4){
                        ybWidget.ShowToaster('success', '操作成功');
                    }
                    if($scope.detailInfo.checkType == 4){
                        ybWidget.ShowMessage("后台创建单据中，请稍后查看盘点列表", MESG_TYPE.Note);
                    }
                    $scope.changeTab(0);
                    getDataList();
                    $scope.markInfo.allChecked = false;
                });
            };

            $scope.sel = { productGroupObj: {} };

            function handleAttachFiles(attachNameStr) {
                if (!attachNameStr) {
                    return [];
                }
                return attachNameStr.split(',').map(an => {
                    const fName = an.split('/').pop()
                    return {
                        fileUrl: an,
                        name: fName,
                        filename: fName,
                        hasUpload: true,
                    }
                })
            }

            $scope.importAttach = function (item) {
                ybWidget.FileUploader({fileList: item.attachFiles || handleAttachFiles(item.attachName), ignoreFormat: true}).then(res => {
                    const fileListTemp  = res.fileList || [];
                    item.attachFiles = fileListTemp;
                    item.attachName = fileListTemp.filter(item => !!item.fileUrl).map(an => an.fileUrl).join(',');

                    const { id, attachName } = item;
                    ybHttp.Post('device', '/inventoryCheck/updateAttach', { id, attachName }).then(function (resp) {
                        if (resp.code !== 0) {
                            ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        }
                    });
                })
            };

            function viewAttach(item) {
                ybWidget.FileUploader({fileList: handleAttachFiles(item.attachName), Type: 'view'})
            }

            function getPDicts () {
                if (!$scope.isJCH) return;
                ybHttp.Post('device', '/serviceBasicDataAgent/searchList', {pCode:"PRODUCTGROUP"}).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return;
                    }
                    $scope.productGroupNoList = resp.value || []
                });
            }
            $scope.exportParam = {
                allUrl: ybHttp.RequestUrl("device", "/inventoryCheck/exportAll")
            };

            $scope.importInventoryAmount = function() {
                var param = {
                    name: "盘点数量",
                    templateReqService: "device",
                    templateReqUrl: "/inventoryCheck/downloadAmountExcel",
                    importReqService: "device",
                    importReqUrl: "/inventoryCheck/importAmountExcel",
                    importErrorUrl: "",
                    otherParams: {
                        checkId: $scope.detailInfo.id
                    }
                };
                ybWidget.ImportFile(param).then(function (data) {
                    viewDetail({id: $scope.detailInfo.id});
                });
            };

            (function () {
                getDataList();
                $scope.setFixedWidth();
                UserContextService.SetBtnPermission(setBtnPermission);
                getPDicts();
            })();
        }])

    ;
})(window, window.angular);
